home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6706 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: news.iadfw.net!usenet
  2. From: Larry Weiss <lfw@iadfw.net>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: 'Freeing' storage with realloc
  5. Date: Sat, 17 Feb 1996 21:06:27 -0600
  6. Organization: ---
  7. Message-ID: <312697B3.618E@iadfw.net>
  8. References: <4fv44f$p2v@news.rz.uni-passau.de> <824596026snz@genesis.demon.co.uk>
  9. NNTP-Posting-Host: dal26-27.ppp.iadfw.net
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b6a (Win16; I)
  14. CC: lfw@oc.com
  15.  
  16. Lawrence Kirby wrote:
  17.  > 
  18.  > In article <4fv44f$p2v@news.rz.uni-passau.de>
  19.  >            berndl@sidonius.uni-passau.de "Klaus Berndl" writes:
  20.  > ... Does realloc 'freeing' the storage behind byte 13?
  21.  > 
  22.  > The extra storage is in principle if not in practice freed. All that is
  23.  > important as far as the program is concerned is that it is illegal to
  24.  > access buf[13] or beyond after the realloc. Whether a particular
  25.  > implementation leaves the storage in place is up to the implementation
  26.  > although any reasonable implementation will make the space available for
  27.  > further allocation where possible. If you still need to use the space as
  28.  > part of that array then that call to realloc is inappropriate and should
  29.  > be removed or changed to a more suitable value.
  30.  > 
  31.  
  32. Also, library functions also are allowed to allocate dynamic memory as they
  33. see fit.   Therefore, for several reasons it is not possible to assume that,
  34. say, if one successfully malloc()'d 1000 bytes and the free()'d them, that
  35. you are guaranteed to be able to malloc() those 1000 bytes later, even though
  36. your code didn't explicitly allocate any space in the interim.  
  37.  
  38. You may malloc() a pool of memory early on, and manage it yourself if you want
  39. more control, but that should be obvious.
  40.